#pragma once

class CWCheckbox;
class CWEdit;
class CwaiLabel;
// CWaiTreeNode view

class CWaiTreeNode: public CWnd
{
public:
	DECLARE_DYNAMIC(CWaiTreeNode)
public:
	CWaiTreeNode(CWaiTreeNode* pParent);           // protected constructor used by dynamic creation
	virtual ~CWaiTreeNode();
	void UpdateLabel();

	void UpdateWindow();

	void setTreeNode(XMLNode* node) {m_pNode = node;}
	XMLNode* getTreeNode() {return m_pNode;}
	void setLabel(const char* label);
	void setContent(const char* content);
	CString getContent();
	void setCheck(BOOL bCheck, BOOL recur = TRUE, BOOL isSave = TRUE);
	void setTextColor(unsigned long color);
	void saveContent();
	void setEditFocus();
	void killEditFocus();

	void foldOrUnfold();
	BOOL isFold() {return m_bFold;}
	void showChildrenWindows(BOOL isShow);

	void relayout();

	

	CWaiTreeNode* GetParentNode() {return m_pParent;}
	CWaiTreeNode* AddChildNode();
	CWaiTreeNode* AddChildNode(XMLNode* node);
	void InsertAfterChild(CWaiTreeNode* pTreeNode, int index);
	CWaiTreeNode* GetChildNode(int index);
	void RemoveChild(CWaiTreeNode* pChildNode, BOOL bRelease = TRUE);
	int CoundChildNodes();

	CWaiTreeNode* InsertSibling();
	void RemoveSelfFromTree();

	CWaiTreeNode* PreviousSibling();
	CWaiTreeNode* NextSibing();
	CWaiTreeNode* InsertEndChild(CWaiTreeNode* pTreeNode);
	CWaiTreeNode* InsertSibling(CWaiTreeNode* pTreeNode);

public:
	virtual void OnDraw(CDC* pDC);      // overridden to draw this view
#ifdef _DEBUG
	virtual void AssertValid() const;
#ifndef _WIN32_WCE
	virtual void Dump(CDumpContext& dc) const;
#endif
#endif
protected:

private:
	CWaiTreeNode* m_pParent;
	CArray<CWaiTreeNode*> m_children;

	CWCheckbox* m_pCheckBox;
	CwaiLabel* m_pLabel;
	CWEdit* m_pEdit;
	XMLNode* m_pNode;

	BOOL m_bFold;
public:
	DECLARE_MESSAGE_MAP()
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
	afx_msg BOOL OnEraseBkgnd(CDC* pDC);
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
};


